from django.db import models
from utils.base_model import BaseModel
from account.models import User


class Blog(BaseModel):
    author = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='作者')
    title = models.CharField(verbose_name='题目', max_length=30)
    content = models.TextField(verbose_name='内容')
    likes = models.IntegerField(verbose_name='点赞', default=0)

    def __str__(self):
        return self.title


# TODO: BlogLike
class BlogLike(BaseModel):
    blog = models.F


class Comment(BaseModel):
    author = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='作者')
    blog = models.ForeignKey(Blog, on_delete=models.CASCADE, verbose_name='博客')
    parent_comment = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, verbose_name='父评论')  # 自关联
    content = models.TextField(verbose_name='内容')

    def __str__(self):
        return self.content
